package com.huanzhidadi.single.collection;

import com.huanzhidadi.single.collection.model.Hero;
import org.springframework.util.StopWatch;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class MapTest {
    public static void main(String[] args) {

        hashMapTest();
    }

    private static void hashMapTest() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("创建Map");
        Random random = new Random();
        Map<String, Hero> heroMap = new HashMap<>();
        for (int i=0; i<200; i++) {
            Hero hero = new Hero("Hero " + random.nextInt(50), i, i);
            heroMap.put(hero.getName(), hero);
        }
        stopWatch.stop();
        System.out.println("总用时：" + stopWatch.getTotalTimeNanos() + "ns");
        System.out.println(heroMap.size());
    }
}
